#!/bin/bash

MYSQL_ROOT_PWD=


# 登陆 MySQL 创建数据库
db_list=(
loong
mg_base
mg_box
mg_dataanalysis
mg_equipment
mg_gateway
mg_inventory
mg_job
mg_knowledge
mg_message
mg_patrol
mg_portal
mg_uaa
mg_voice
mg_backstage
mg_airflow
mg_activiti
mg_user_activity
)

# node04
for db_name in ${db_list[@]}; do
    mysql -uroot -p$MYSQL_ROOT_PWD -e "CREATE DATABASE IF NOT EXISTS ${db_name};"
done


CREATE USER 'mango'@'%' IDENTIFIED BY '随机密码';
GRANT ALL ON loong.* TO 'mango'@'%';
GRANT ALL ON mango_20191119_1942.* TO 'mango'@'%';
GRANT ALL ON mg_activiti.* TO 'mango'@'%';
GRANT ALL ON mg_airflow.* TO 'mango'@'%';
GRANT ALL ON mg_backstage.* TO 'mango'@'%';
GRANT ALL ON mg_base.* TO 'mango'@'%';
GRANT ALL ON mg_box.* TO 'mango'@'%';
GRANT ALL ON mg_build.* TO 'mango'@'%';
GRANT ALL ON mg_dataanalysis.* TO 'mango'@'%';
GRANT ALL ON mg_equipment.* TO 'mango'@'%';
GRANT ALL ON mg_gateway.* TO 'mango'@'%';
GRANT ALL ON mg_inventory.* TO 'mango'@'%';
GRANT ALL ON mg_job.* TO 'mango'@'%';
GRANT ALL ON mg_knowledge.* TO 'mango'@'%';
GRANT ALL ON mg_message.* TO 'mango'@'%';
GRANT ALL ON mg_patrol.* TO 'mango'@'%';
GRANT ALL ON mg_portal.* TO 'mango'@'%';
GRANT ALL ON mg_uaa.* TO 'mango'@'%';
GRANT ALL ON mg_user_activity.* TO 'mango'@'%';
GRANT ALL ON mg_voice.* TO 'mango'@'%';
flush privileges;
show grants for 'mango'@'%';

# GRANT ALL ON *.* TO 'mango'@'%';


# mysqldump backup
mysqldump -uroot -pzaq1@WSX mg_equipment -R > mg_equipment_20201117.sql


# mysqldump backup  -R 备份函数 --ignore-table 备份跳过指定表(jhi_persistent_audit_evt_data/jhi_persistent_audit_event)
mysqldump -uroot -pzaq1@WSX mg_uaa -R --ignore-table=mg_uaa.jhi_persistent_audit_evt_data --ignore-table=mg_uaa.jhi_persistent_audit_event > mg_uaa_skip_log.sql

# 只备份某个表
mysqldump -uroot -pzaq1@WSX mg_uaa databasechangelog -R > mg_uaa_databasechangelog.sql